<!--
Copyright (c) 2008 Google Inc.
You are free to copy and use this sample.
License can be found here: http://code.google.com/apis/ajaxsearch/faq/#license
--> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
        <title>Google PK</title>
        <style type="text/css">
        </style>
		<!--google analytics-->
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-7661217-1");
pageTracker._trackPageview();
} catch(err) {}</script>


        <!-- Replace with http://www.google.com/jsapi -->
        <script src="http://www.google.com/jsapi" type="text/javascript">
        </script>
        <script type="text/javascript">
            google.load('search', '1');
            google.load("visualization", "1", {
                packages: ["table"]
            });
            
            var gSearchForm;
            var gLocalSearch;
            var data;
            function OnLoad(){
                gSearchForm = new google.search.SearchForm(false, document.getElementById("searchform"));
                gSearchForm.setOnSubmitCallback(null, CaptureForm);
                
                //gWebSearch = new google.search.WebSearch();
                //gWebSearch.setSearchCompleteCallback(null, OnWebSearch);
                //                gSearchForm.execute("this is the example");
                
                data = new google.visualization.DataTable();
                data.addColumn('string', 'Query');
                data.addColumn('number', 'Estimated Result Count');
				gSearchForm.input.focus();
                
            }
            

//函数定义-开始
			function OnWebSearch(){
                if (!gWebSearch.results) 
                    return;
                var id = data.addRow();
                //data.setCell(id, 0, this.rst[0]);
				//var query;
				data.setCell(id, 0, this.query);
				
                data.setCell(id, 1, eval(gWebSearch.cursor.estimatedResultCount));
                
                var table = new google.visualization.Table(document.getElementById('table_div'));
                var formatter = new google.visualization.TableBarFormat({
                    width: 120
                });
                formatter.format(data, 1); // Apply formatter to second column
                data.sort([{
                    column: 1,
                    desc: true
                }]);
                
                table.draw(data, {
                    allowHtml: true,
                    showRowNumber: true,
                    sort: 'enable'
                });
            }
			
//函数定义-结束
            
            // Cancel the form submission, executing an AJAX Search API search.
            function CaptureForm(searchForm){
                if (searchForm.input.value) {
                    rst = searchForm.input.value.split(",");
                    
                    //					document.write(rst);
                    for (var i = 0; i < rst.length; i++) {
						var callBack = new OnWebSearch();
						callBack.query=rst[i];
						
                        gWebSearch = new google.search.WebSearch();//注意，这里重建了一个webSearch
                        gWebSearch.setSearchCompleteCallback(null, OnWebSearch);
						
                        gWebSearch.execute(rst[i]);
                    }
                    //					for (var q in rst)
                    //	                    gWebSearch.execute(q);
                }
                searchForm.input.value = "";
                return false;
            }
            
            google.setOnLoadCallback(OnLoad, true);
        </script>
    </head>
    <body>
        <h1>Google PK</h1>
        <p>
            逐个输入关键字，通过google搜索的结果数比较它们的热度~
        </p>
		<div id = "left" >
		
	        <div id="placelist">
	            <div id="search">
	                <div id="searchform">
	                </div>
	            </div>
	            <div id="results">
	                <div id="searchwell">
	                </div>
	                <div id="table_div">
	                </div>
	            </div>
	        </div>
		</div>
    </body>
</html>
</script>
